package com.ericsson.bscs.cmstest.clients ;

import java.util.logging.Logger ;

import com.lhs.ccb.func.ect.ComponentException ;

public class CustomerBonusPointsRead implements Executor, Runnable
{
	private final static Logger log = Logger.getLogger(CustomerBonusPointsRead.class.getCanonicalName()) ;

	private SOILoaderDBHandler soidb ;

	@Override
	public void run()
	{
		// BODY OF BUSINESS LOGIC
		try
		{
			final BaseTestHandler baseTestHandler = new BaseTestHandler() ;
			System.out.println("\nSOI Initialize...") ;
			baseTestHandler.init() ;

			long customerId ;
			final String exeName = Thread.currentThread().getName() ;
			while (!Thread.currentThread().isInterrupted())
			{
				customerId = soidb.nextCustomerId() ;
				System.out.println("\n") ;
				System.out.println(exeName + ": Begin with CS_ID=" + customerId) ;
				try
				{
					System.out.println(exeName + ": Lookup and Login") ;
					baseTestHandler.connect() ;
					System.out.println(exeName + ": Executing") ;
					baseTestHandler.handleCustomerBonusPointsRead(baseTestHandler.getServiceAccessor(), customerId) ;
					// baseTestHandler.commit();
					System.out.println(exeName + ": Disconnect") ;
					baseTestHandler.disconnect() ;
				}
				catch (final Exception e)
				{
					if (e instanceof ComponentException)
					{
						final ComponentException compEx = (ComponentException) e ;
						System.out.println(exeName + ":" + compEx.getErrorCode()) ;
						final java.lang.Object[] arguments = compEx.getArguments() ;
						for (final Object argument : arguments)
							System.out.println(exeName + ":\t" + argument) ;
						System.out.println() ;
					}
					e.printStackTrace() ;
				}

				System.out.println(exeName + ": End with CS_ID=" + customerId) ;
				System.out.println("\n") ;
				Thread.sleep(200) ;
			}

		}
		catch (final Exception e)
		{
			e.printStackTrace() ;
		}
	}

	@Override
	public void setDBHandler(final SOILoaderDBHandler soidb)
	{
		this.soidb = soidb ;
	}
}
